package com.five.controller.backstage;

import com.five.dao.backstage.StaffDao;
import com.five.entity.backstage.TStaff;
import com.five.util.LayTable;
import com.five.util.Page;
import com.five.util.PrintJsonData;
import com.five.util.TransBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.swing.*;
import java.util.List;
import java.util.Map;

/**
 * @Author: 王登峰
 * @Description:
 * @Date: 2020/11/23 16:01
 */
@Controller
public class StaffController {
    @Autowired
    private StaffDao staffDao;
    //给方法绑定一个  路由  url
    @RequestMapping("/selectStaff")
    //返回接送数据
    @ResponseBody
    public LayTable selectStaff(Page pageInfo1,TStaff tStaff){
       // System.out.println(pageInfo1.toString());
        List<Map> list = staffDao.selectStaff(pageInfo1,tStaff);
        //System.out.println(list);
        int count = staffDao.count(tStaff);
        List populate = TransBean.populate(TStaff.class, list);
        LayTable layTable = new LayTable(count,populate);
        return layTable;
    }

    @RequestMapping("/selectDept")
    @ResponseBody
    public List<Map> selectDept(){
        return staffDao.selectDept();
    }

    @RequestMapping("/selectRole")
    @ResponseBody
    public List<Map> selectRole(Integer id){

        return staffDao.selectRole(id);
    }

    @RequestMapping("/selectRoleId")
    @ResponseBody
    public Map selectRoleId(Integer id){
        List<Map> map = staffDao.selectRoleId(id);
        return map.get(0);
    }


    @RequestMapping("/addStaff")
    @ResponseBody
    public void addStaff(TStaff tStaff){
        staffDao.addStaff(tStaff);
        if(tStaff.getId()==null){
            String id = staffDao.selectID(tStaff.getNstaff());
            staffDao.addStaffpwd(tStaff.getNstaff(),id);
        }else {
            staffDao.upadetaffname(tStaff.getNstaff(),tStaff.getId()+"");
        }

    }
    @RequestMapping("/liZhi")
    @ResponseBody
    public void liZhi(TStaff tStaff){
        staffDao.liZhi(tStaff);
    }


}
